﻿using AutoMapper;
using QYmall.Core.Model.Models;
using QYmall.Core.Model.ViewModels;

namespace QYmall.Core.Model.Profiles
{
    public class MerchantProfile : Profile
    {
        public MerchantProfile()
        {
            //商户菜单
            //将源数据映射到DTO
            CreateMap<MerchantMenu, MerchantMenuDto>();
            CreateMap<MerchantMenu, MerchantMenuEditDto>();
            //将DTO映射到源数据
            CreateMap<MerchantMenuEditDto, MerchantMenu>();

            //商户信息
            //源数据映射到DTO
            CreateMap<Merchants, MerchantsDto>()
                .ForMember(
                    dest => dest.UserName,
                    opt =>
                    {
                        opt.MapFrom(src => src.User != null ? src.User.UserName : null);
                    }
                ).ForMember(
                    dest => dest.CategoryTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Category != null ? src.Category.Title : null);
                    }
                ).ForMember(
                    dest => dest.StoreTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Store != null ? src.Store.Title : null);
                    }
                );
            CreateMap<Merchants, MerchantsClientDto>()
                .ForMember(
                    dest => dest.UserName,
                    opt =>
                    {
                        opt.MapFrom(src => src.User != null ? src.User.UserName : null);
                    }
                ).ForMember(
                    dest => dest.CategoryTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Category != null ? src.Category.Title : null);
                    }
                ).ForMember(
                    dest => dest.StoreTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Store != null ? src.Store.Title : null);
                    }
                );
            CreateMap<Merchants, MerchantsEditDto>();
            CreateMap<Merchants, MerchantsBaseDto>();
            CreateMap<Merchants, MerchantsClientDto>();
            //DTO映射到源数据
            CreateMap<MerchantsEditDto, Merchants>();
            CreateMap<MerchantsBaseDto, Merchants>();
            CreateMap<MerchantsBaseDto, MerchantsEditDto>();

            //商户分类
            //源数据映射到DTO
            CreateMap<MerchantCategory, MerchantCategoryDto>();
            CreateMap<MerchantCategory, MerchantCategoryEditDto>();
            //DTO映射到源数据
            CreateMap<MerchantCategoryEditDto, MerchantCategory>();

            //店铺类型
            //源数据映射到DTO
            CreateMap<MerchantStore, MerchantStoreDto>();
            CreateMap<MerchantStore, MerchantStoreEditDto>();
            //DTO映射到源数据
            CreateMap<MerchantStoreEditDto, MerchantStore>();

            //商户收款方式
            //源数据映射到DTO
            CreateMap<MerchantPayinfo, MerchantPayinfoDto>();
            CreateMap<MerchantPayinfo, MerchantPayinfoEditDto>();
            //DTO映射到源数据
            CreateMap<MerchantPayinfoEditDto, MerchantPayinfo>();

            //商户提现申请
            //源数据映射到DTO
            CreateMap<MerchantCash, MerchantCashDto>();
            CreateMap<MerchantCash, MerchantCashListDto>()
                .ForMember(
                    dest => dest.MerchantTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Merchant != null ? src.Merchant.Title : null);
                    }
                );
            //DTO映射到源数据
            CreateMap<MerchantCashEditDto, MerchantCash>();
            CreateMap<MerchantCashHandleDto, MerchantCash>();

            //商户资金日志
            //源数据映射到DTO
            CreateMap<MerchantAmountLog, MerchantAmountLogDto>()
                .ForMember(
                    dest => dest.MerchantTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Merchant != null ? src.Merchant.Title : null);
                    }
                );
            CreateMap<MerchantAmountLog, MerchantAmountLogEditDto>();
            //DTO映射到源数据
            CreateMap<MerchantAmountLogEditDto, MerchantAmountLog>();

            //商户收藏关注
            //源数据映射到DTO
            CreateMap<MerchantFavorite, MerchantFavoriteDto>()
                .ForMember(
                    dest => dest.MerchantTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Merchant != null ? src.Merchant.Title : null);
                    }
                );
            CreateMap<MerchantFavorite, MerchantFavoriteEditDto>();
            //DTO映射到源数据
            CreateMap<MerchantFavoriteEditDto, MerchantFavorite>();

            //店铺文章分类
            //源数据映射到DTO
            CreateMap<MerchantArticleCategory, MerchantArticleCategoryDto>();
            CreateMap<MerchantArticleCategory, MerchantArticleCategoryEditDto>();
            //DTO映射到源数据
            CreateMap<MerchantArticleCategoryEditDto, MerchantArticleCategory>();

            //店铺文章
            //源数据映射到DTO
            CreateMap<MerchantArticle, MerchantArticleDto>()
                .ForMember(
                    dest => dest.MerchantTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Merchant != null ? src.Merchant.Title : null);
                    }
                ).ForMember(
                    dest => dest.MerchantAvatar,
                    opt =>
                    {
                        opt.MapFrom(src => src.Merchant != null ? src.Merchant.Avatar : null);
                    }
                ).ForMember(
                    dest => dest.CategoryTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Category != null ? src.Category.Title : null);
                    }
                );
            CreateMap<MerchantArticle, MerchantArticleEditDto>();
            CreateMap<MerchantArticle, MerchantArticleClientDto>()
                 .ForMember(
                    dest => dest.MerchantTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Merchant != null ? src.Merchant.Title : null);
                    }
                ).ForMember(
                    dest => dest.MerchantAvatar,
                    opt =>
                    {
                        opt.MapFrom(src => src.Merchant != null ? src.Merchant.Avatar : null);
                    }
                ).ForMember(
                    dest => dest.CategoryTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.Category != null ? src.Category.Title : null);
                    }
                );
            //DTO映射到源数据
            CreateMap<MerchantArticleEditDto, MerchantArticle>();
        }
    }
}
